package xiegd.study.builder;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Author: xieguangda
 * @Description:
 * @Date: 2023/9/7 10:37
 */
@Getter
// Make constructor private so object cannot be created outside the class
// Allowing only PersonBuilder.build to create an instance of the class
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Person {

    private String firstName;
    private String lastName;
    private String email;
    private String mobile;

    // PersonBuilder can only be created with  firstName, lastName
    // which implies that Person object ll always be instantiated with firstName & lastName
    public static PersonBuilder builder(String firstName, String lastName) {
        return new PersonBuilder(firstName, lastName);
    }

    public static class PersonBuilder {

        private final String firstName;
        private final String lastName;
        private String email;
        private String mobile;

        // Make constructor private so object cannot be created outside the class
        // Allowing only Person.builder to create an instance of  PersonBuilder
        private PersonBuilder(String firstName, String lastName) {
            this.firstName = firstName;
            this.lastName = lastName;
        }

        public PersonBuilder email(String email) {
            this.email = email;
            return this;
        }

        public PersonBuilder mobile(String mobile) {
            this.mobile = mobile;
            return this;
        }

        public Person build() {
            return new Person(firstName, lastName, email, mobile);
        }

    }

}
